package shen.yue.example.one;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.widget.EditText;
import android.widget.Toast;

/**
 * Created by jiangzhuolei on 2017/8/3.
 */

public class BaseActivity extends Activity {

    public final String TAG = getClass().getSimpleName();


    private ProgressDialog waitingDialog;

    public void showDialog1(String str){
        /* @setIcon 设置对话框图标
         * @setTitle 设置对话框标题
         * @setMessage 设置对话框消息提示
         * setXXX方法返回Dialog对象，因此可以链式设置属性
         */
        AlertDialog.Builder normalDialog = new AlertDialog.Builder(this);
        normalDialog.setTitle("提示");
        normalDialog.setMessage(str);
        normalDialog.setPositiveButton("确定",
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        //...To-do
                    }
                });
        normalDialog.show();
    }


    public void showDialog2() {
    /* 等待Dialog具有屏蔽其他控件的交互能力
     * @setCancelable 为使屏幕不可点击，设置为不可取消(false)
     * 下载等事件完成后，主动调用函数关闭该Dialog
     */

        if(waitingDialog == null){
            waitingDialog=new ProgressDialog(this);
        }
        waitingDialog.setTitle("提示");
        waitingDialog.setMessage("等待中...");
        waitingDialog.setIndeterminate(true);
        waitingDialog.setCancelable(false);
        waitingDialog.show();
    }


    public void missDialog2() {
        if(waitingDialog!= null&&waitingDialog.isShowing()){
            waitingDialog.dismiss();
        }
    }


    public void startActivity(Class activity){
        Intent intent = new Intent(this,activity);
        startActivity(intent);
    }

    public void showToast(String str){
        Toast.makeText(this,str,Toast.LENGTH_SHORT).show();
    }


    public EditText getEditText(int id){
        return (EditText)findViewById(id);
    }

}
